# 无重叠区间：
# 给定一个区间的集合，找到需要移除区间的最小数量，使剩余区间互不重叠。

class Solution:
    def eraseOverlapIntervals(self, intervals: list[list[int]]) -> int:
        n = intervals.__len__()
        return n - self.intervalSchedule(intervals)

    def intervalSchedule(self, intvs: list[list[int]]) -> int:
        if intvs.__len__() == 0: return 0
        intvs.sort(key=lambda t: t[1])
        count = 1
        x_end = intvs[0][1]
        for interval in intvs:
            start = interval[0]
            if start >= x_end:
                count += 1
                x_end = interval[1]
        return count

if __name__=="__main__":
    a=[[1,2],[2,3],[2,4],[1,3],[0,2]]
    a.sort(key=lambda t:t[1])
    print(a)
